using HKB.Common;
using System;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class LogBll
	{
		private Conn conn;
		public LogBll(Conn _conn)
		{
			this.conn = _conn;
		}
		public LogBll()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public DataTable GetLogById(int ID)
		{
			return this.conn.GetDataTable("Select * [HL_Log] Where LogID=" + ID);
		}
		public bool AddLog(string LogType, string VisitUrl, string OperatObject, DateTime OperaTime, string Operator, string OperatorIP, string OperatorHostName, int LoginErrTimes, string AppModule)
		{
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@LogType", DbType.String, LogType),
				this.conn.CreateParameter("@VisitUrl", DbType.String, VisitUrl),
				this.conn.CreateParameter("@OperatObject", DbType.String, OperatObject),
				this.conn.CreateParameter("@OperaTime", DbType.DateTime, OperaTime),
				this.conn.CreateParameter("@Operator", DbType.String, Operator),
				this.conn.CreateParameter("@OperatorIP", DbType.String, OperatorIP),
				this.conn.CreateParameter("@OperatorHostName", DbType.String, OperatorHostName),
				this.conn.CreateParameter("@LoginErrTimes", DbType.Int32, LoginErrTimes),
				this.conn.CreateParameter("@AppModule", DbType.String, AppModule)
			};
			return this.conn.Execute("insert into [HL_Log](LogType, VisitUrl, OperatObject, OperaTime, Operator, OperatorIP, OperatorHostName, LoginErrTimes, AppModule) values(@LogType, @VisitUrl, @OperatObject, @OperaTime, @Operator, @OperatorIP, @OperatorHostName, @LoginErrTimes, @AppModule)", parameters) == 1;
		}
		public bool DeleteLog(int ID)
		{
			return this.conn.Execute(string.Concat(new object[]
			{
				"Delete From [HL_Log] Where DateDiff(hh,OperaTime,'",
				DateTime.Now,
				"')>24 and LogID=",
				ID
			})) == 1;
		}
		public bool DeleteLog(string IDs)
		{
			return this.conn.Execute(string.Concat(new object[]
			{
				"Delete From [HL_Log] Where DateDiff(hh,OperaTime,'",
				DateTime.Now,
				"')>24 and LogID in (",
				IDs,
				")"
			})) >= 1;
		}
		public bool DeleteLogBf(DateTime m_time)
		{
			return this.conn.Execute(string.Concat(new object[]
			{
				"Delete From [HL_Log] Where  DateDiff(hh,OperaTime,'",
				DateTime.Now,
				"')>24 and datediff(dd,OperaTime,'",
				m_time,
				"')>=0"
			})) >= 1;
		}
	}
}
